package functions;

import functions.CRSTlzw;

public class NCD {
	// function to return distance value between two tests based on LZW algorithm
	public static Double getNCD(String test1, String test2)
	{
		String concatTests12 = test1 +", "+ test2;
		String concatTests21 = test2 +", "+ test1;
		
		int cTest1 = CRSTlzw.LZWcompressionValue(test1);	// lzw length on test1
		int cTest2 = CRSTlzw.LZWcompressionValue(test2);	// lzw length on test2
		int cTest12 = CRSTlzw.LZWcompressionValue(concatTests12);	// lzw length on concatenation of test1 and test 2
		int cTest21 = CRSTlzw.LZWcompressionValue(concatTests21);	// lzw length on concatenation of test2 and test 1
			
		int x= getMinVal(cTest12, cTest21);
		int y= getMinVal(cTest1, cTest2);
		int z= getMaxVal(cTest1, cTest2);
		double result =(double) (x - y)/z;
		
		return result;
	}
	
	
	private static int getMinVal(Integer x, Integer y)
	{
		if(x>=y)
			return y;
		else
			return x;
	}
	
	private static int getMaxVal(Integer x, Integer y)
	{
		if(x>=y)
			return x;
		else
			return y;
	}
	
}
